package com.baoyouqun.controller.back;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.DemandCollectionCreateCmd;
import com.baoyouqun.domain.Query.DemandCollectionQuery;
import com.baoyouqun.domain.UpdateCmd.DemandCollectionUpdateCmd;
import com.baoyouqun.domain.VO.DemandCollectionVO;
import com.baoyouqun.service.DemandCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/back/demandCollection")
@Api(tags = "需求互动表（收藏，取消收藏）管理接口")
public class DemandCollectionController {

    @Resource
    private DemandCollectionService demandCollectionService;

    @PostMapping("create")
    @ApiOperation("新增需求互动表（收藏，取消收藏）")
    public SingleResponse<DemandCollectionVO> create(DemandCollectionCreateCmd cmd) {
        return demandCollectionService.create(cmd);
    }

    @PutMapping("update")
    @ApiOperation("修改需求互动表（收藏，取消收藏）")
    public Response update(DemandCollectionUpdateCmd cmd) {
        return demandCollectionService.update(cmd);
    }

    @DeleteMapping("delete")
    @ApiOperation("根据ID删除需求互动表（收藏，取消收藏）")
    public Response delete(String id) {
        demandCollectionService.removeById(id);
        return Response.buildSuccess();
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询需求互动表（收藏，取消收藏）")
    public SingleResponse<DemandCollectionVO> selectById(String id) {
        return SingleResponse.of(demandCollectionService.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询需求互动表（收藏，取消收藏）")
    public PageResponse<DemandCollectionVO> page(DemandCollectionQuery query) {
        IPage<DemandCollectionVO> page = demandCollectionService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}